

ALTER  proc sp_save_salesperson_list
@customerId int,
@salespersonid int
as
begin

	declare @status_id int
	
	if(( select count(*) from Customer_SalesPerson_relationship where Customer_ID = @customerId and SalesPerson_ID = @salespersonid) = 0)
	begin
		select @status_id = RelationshipStatus_ID from Customer_Relationship_Status where Name = 'Active'
		
		insert into customer_salesperson_relationship(Customer_ID, SalesPerson_ID, RelationshipStatus_ID) values (@customerId, @salespersonid, @status_id)
	end
	else
	begin
		select @status_id = RelationshipStatus_ID from Customer_Relationship_Status where Name = 'Active' -- Added by Veeru ( 29th Nov 2004)
		update Customer_Salesperson_Relationship set Customer_ID = @customerId, SalesPerson_ID = @salespersonid, RelationshipStatus_ID = @status_id where Customer_ID = @customerId and SalesPerson_Id = @salespersonid
	end		
end
